//
//  HMToplistDetailCell.m
//  HowToDo
//
//  Created by Stan on 2017-01-05.
//  Copyright © 2017 KY. All rights reserved.
//

#import "HMToplistDetailCell.h"
#import "HMShoppingCarTool.h"



@interface HMToplistDetailCell ()

//@property(strong,nonatomic)HMShoppingCarBtn *shoppingCartBtn;
//@property (nonatomic, assign) CGFloat cellPrice;

@end

@implementation HMToplistDetailCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createUI];
    }
    return self;
}

- (void)createUI{
//    添加封面
    self.coverPhotoImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:self.coverPhotoImageView];
    
    self.coverPhotoImageView.image = [UIImage imageNamed:@"201612271441573272"];
    
    self.coverPhotoImageView.contentMode = UIViewContentModeScaleAspectFit;
    
    [self.coverPhotoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.offset(15);
        make.bottom.offset(-15);
        make.width.offset(85);
        make.height.mas_lessThanOrEqualTo(113);
    }];
    
//    设置标题
    self.resourceNameLabel = [UILabel hm_labelWithText:@"怎样的一个人？可以给我勇气与你慢慢变老" fontSize:k_FONT_NORMAL colorWithHex:0x333333];
    [self.contentView addSubview:self.resourceNameLabel];
    
    [self.resourceNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(19);
        make.left.equalTo(self.coverPhotoImageView.mas_right).offset(17);
        make.right.offset(-10);
    }];
    
//    设置简介
    self.resourceContentLabel = [UILabel hm_labelWithText:@"怎样的一个人？可以给我勇气与你慢慢变老怎样的一个人？可以给我勇气与你慢慢变老" fontSize:12.0 colorWithHex:0x666666];
    [self.contentView addSubview:self.resourceContentLabel];
    
    self.resourceContentLabel.numberOfLines = 2;
    
    [self.resourceContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.resourceNameLabel.mas_bottom).offset(10);
        make.left.equalTo(self.resourceNameLabel.mas_left).offset(0);
        make.right.offset(-10);
    }];
    
//    设置节约时长
    self.resourceEnclosureLabel = [UILabel hm_labelWithText:@"解读版：平均节省3小时阅读时间" fontSize:12.0 colorWithHex:0x666666];
    [self.contentView addSubview:self.resourceEnclosureLabel];
    
    
    [self.resourceEnclosureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.resourceContentLabel.mas_bottom).offset(10);
        make.left.equalTo(self.resourceNameLabel.mas_left).offset(0);
        make.right.offset(-10);
    }];
    
    
//    设置价格
    self.priceLabel = [UILabel hm_labelWithText:@"¥4.99" fontSize:12.0 colorWithHex:0xffa42f];
    [self.contentView addSubview:self.priceLabel];
    
    
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.resourceNameLabel.mas_left).offset(0);
        make.bottom.offset(-26);
    }];
    
    //    设置购物车的btn
    self.shoppingCartBtn = [[HMShoppingCarBtn alloc]init];
    [self.contentView addSubview:self.shoppingCartBtn];
   
    [self.shoppingCartBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-14);
        make.right.equalTo(self.contentView.mas_right).offset(-20);
    }];
    
//    [self.shoppingCartBtn addTarget:self action:@selector(shoppingCartBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
}

//- (void)shoppingCartBtnClick:(UIButton *)btn
//{
//    if (btn.selected)
//    {
//        self.cellPrice -= self.priceLabel.text.integerValue;
//    }
//    else
//    {
//        self.cellPrice += self.priceLabel.text.integerValue;
//    }
//    
//    if (self.allPrice) {
//        self.allPrice(self.cellPrice);
//    }
//    
//}


- (void)setToplistDetailModel:(HMToplist *)toplistDetailModel{
    _toplistDetailModel = toplistDetailModel;
    
    self.resourceID = toplistDetailModel.resource_id;
    self.resourceNameLabel.text = toplistDetailModel.resource_name;
    self.resourceContentLabel.text = toplistDetailModel.resource_content;
    self.resourceEnclosureLabel.text = [NSString stringWithFormat:@"解读版：平均节省%@小时阅读时间",toplistDetailModel.resource_enclosure];
    
    self.priceLabel.text = [NSString stringWithFormat:@"¥%@",toplistDetailModel.price];
//    self.priceLabel.text = toplistDetailModel.price;
    [self.coverPhotoImageView sd_setImageWithURL:[NSURL URLWithString:toplistDetailModel.image_url] placeholderImage:[UIImage imageNamed:@"201612271441573272"]];
    
    //    给购物车的Btn赋值
    self.shoppingCartBtn.resource_id = toplistDetailModel.resource_id;
    self.shoppingCartBtn.image_url = toplistDetailModel.image_url;
    self.shoppingCartBtn.resource_name = toplistDetailModel.resource_name;
    self.shoppingCartBtn.resource_content = toplistDetailModel.resource_content;
    self.shoppingCartBtn.resource_enclosure = toplistDetailModel.resource_enclosure;
    self.shoppingCartBtn.price = toplistDetailModel.price.description;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    //    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    
}

@end
